﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Physis.Client.Models.Configuration {

    public class ConfigurationItemModel : ApplicationModel {

        #region Public Properties

        public virtual Core.CoreConfigurationObject ConfigurationItem { get { return null; } }

        public virtual Int64 ConfigurationItemId { set { /* DO NOTHING */ } }

        public virtual String ConfigurationItemType {

            get {

                if (ConfigurationItem == null) { return String.Empty; }

                return ConfigurationItem.ObjectType;

            }

        }

        public virtual String ConfigurationItemName {

            get {

                if (ConfigurationItem == null) { return String.Empty; }

                return ConfigurationItem.Name;

            }

        }

        #endregion


        #region Public Methods

        public override void UpdateValues (System.Collections.Specialized.NameValueCollection form) {

            base.UpdateValues (form);


            // RELOAD BASE OBJECT FROM DATABASE 

            ConfigurationItemId = Data.Readers.FormReader.Int64FromForm (form, "ConfigurationItem.Id");


            // LOAD FIELDS FROM FORM INTO PROPERTIES FOR CORE CONFIGURATION OBJECT 

            ConfigurationItem.Name = Data.Readers.FormReader.StringFromForm (form, "ConfigurationItem.Name");

            ConfigurationItem.Description = Data.Readers.FormReader.StringFromForm (form, "ConfigurationItem.Description");

            ConfigurationItem.Enabled = Data.Readers.FormReader.BooleanFromForm (form, "ConfigurationItem.Enabled");

            return;

        }

        #endregion 

    }

}
